fix(session): pin channel open/top-up read-back to receipt block#617
Merged
Merged
Conversation
After broadcasting an escrow open/top-up, the server re-reads on-chain channel state at `latest` and checks it against the receipt. Behind a load-balanced RPC, that read can land on a replica that has not yet imported the block the transaction was mined in, returning empty/stale state. Verification then fails with a spurious 402 "on-chain channel state does not match open receipt" even though the transaction succeeded and the caller was charged. Pin the read-back to the block from the transaction receipt so any node either returns authoritative state or errors (and is retried) instead of answering with a lagging view. Also retry transient read failures while the replica catches up. Amp-Thread-ID: https://ampcode.com/threads/T-019f2769-0fe3-76ee-a0f0-63b126fd3da0 Co-authored-by: Amp <amp@ampcode.com>
commit: |
brendanjryan
approved these changes
Jul 4, 2026
brendanjryan
left a comment
Collaborator
There was a problem hiding this comment.
Good find -- thank you!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After broadcasting an escrow open/top-up, the server re-reads on-chain channel state at
latestand validates it against the receipt. Behind a load-balanced RPC, that read can land on a replica that hasn't yet imported the block the transaction was mined in, returning empty/stale state. Verification then fails with a spurious402 on-chain channel state does not match open receipteven though the transaction succeeded and the caller was charged.This pins the read-back to the block from the transaction receipt, so a node either returns authoritative state or errors (and is retried) instead of answering with a lagging view. Transient read failures are retried while the replica catches up.
Tests cover block-pinning (read-back targets the receipt block, not
latest) and the retry helper (success, retry-until-success, and exhaustion).